﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Content;
using Brain.Skinning;
using Microsoft.Xna.Framework;

namespace Brain_Skinning
{
    public class SkinnedAnimationClipContent
    {
        [ContentSerializer(ElementName = "AnimationClips")]
        public Dictionary<string, SkinnedAnimationClip> AnimationClips { get; protected set; }

        internal SkinnedAnimationClipContent(Dictionary<string, SkinnedAnimationClip> clips)
        {
            this.AnimationClips = clips;
        }

        internal void Write(ContentWriter output)
        {
            output.Write(AnimationClips.Count);
            foreach (KeyValuePair<string, SkinnedAnimationClip> clip in AnimationClips)
            {
                output.Write(clip.Key);
                output.Write(clip.Value.Duration);

                output.Write(clip.Value.Bones.Length);
                foreach (BoneKeyFrameCollection frameCol in clip.Value.Bones)
                {
                    output.Write(frameCol.BoneIndex);

                    output.Write(frameCol.KeyFrames.Length);
                    foreach (Frame_Skinned frame in frameCol.KeyFrames)
                    {
                        output.Write(frame.Time);
                        output.Write(frame.Position);
                        output.Write(frame.Orientation);
                        output.Write(frame.Scale);
                    }
                }
            }
        }
    }
}
